from threading import Thread
from time import sleep, ctime

"""自定义线程类"""

# 1
class MyThread1(Thread):
    def __init__(self, sex):
        self.sex = sex
        # 加载父类__init__
        super().__init__()

    def f1(self):
        print("step1")

    def f2(self):
        print("step2")

    def run(self):
        self.f1()
        self.f2()

# 2
class MyThread2(Thread):
        def __init__(self, target, args=(), kwargs=None):
            super().__init__()
            if kwargs is None:
                kwargs = {}
            self.target = target
            self.args = args
            self.kwargs = kwargs

        def run(self):
            self.target(*self.args, **self.kwargs)



def player(sec, song):
    for i in range(3):
        print("Player %s  %s" % (song, ctime()))
        sleep(sec)


t = MyThread2(target=player, args=(3,), kwargs={"song": "凉凉"})
t.start()
t.join()
